package cn.tank;

import cn.tank.service.CallMethodThread;
import cn.tank.service.IHelloService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ClientBoot{

    public static void main(String[] args) throws IOException{
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfig.class);
        context.start();
        //System.in.read();

        ExecutorService threadPool = Executors.newFixedThreadPool(150);

        for(int i = 0;i<50;i++){
            CallMethodThread callMethod1 = new CallMethodThread(context.getBean(IHelloService.class), (short) 1);
            CallMethodThread callMethod2 = new CallMethodThread(context.getBean(IHelloService.class), (short) 2);
            CallMethodThread callMethod3 = new CallMethodThread(context.getBean(IHelloService.class), (short) 3);

            threadPool.execute(callMethod1);
            threadPool.execute(callMethod2);
            threadPool.execute(callMethod3);
        }
        while (true){
            System.in.read();
        }
    }



    @EnableDubbo
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan("cn.tank.bean")
    static public class ProviderConfig{

    }
}
